using System;
using System.Collections.Generic;
using System.Text;
using SDMX_Common = SDMX_ML.Framework.Common;

namespace SDMX_ML.Framework.Structure
{
    public class CodeType
    {
        private SDMX_Common.IDType _value;
        private List<SDMX_Common.TextType> _description;
        private string _urn;
        private SDMX_Common.IDType _parentCode;
        private SDMX_Common.AnnotationsType _annotations;

        /// <summary>
        /// Constructor. Use this only if you also use properties to add description.
        /// </summary>
        /// <param name="value">Codevalue.</param>
        public CodeType(SDMX_Common.IDType value)
        {
            if (value != null)
            {
                _value = value;
            }
            else
            {
                throw new Exception("Attribute value and element description are required in CodeType!");
            }

            _description = new List<SDMX_Common.TextType>();
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="value">Codevalue.</param>
        /// <param name="description">Description with TextType defining language. If Language is not supplied language en is assumed.</param>
        public CodeType(SDMX_Common.IDType value, SDMX_Common.TextType description)
        {
            if (value != null & description != null)
            {
                _description = new List<SDMX_Common.TextType>();
                _value = value;
                _description.Add(description);
            }
            else
            {
                throw new Exception("Attribute value and element description are required in CodeType!");
            }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="value">Codevalue.</param>
        /// <param name="description">Description of codevalue. Endglish is default language.</param>
        public CodeType(string value, string description)
        {
            if (!String.IsNullOrEmpty(value) & !String.IsNullOrEmpty(description))
            {
                _description = new List<SDMX_Common.TextType>();

                SDMX_Common.IDType code = new SDMX_Common.IDType(value);
                _value = code;

                SDMX_Common.TextType desc = new SDMX_Common.TextType(description);
                _description.Add(desc);
            }
            else
            {
                throw new Exception("Attribute value and element description are required in CodeType!");
            }
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="value">Codevalue.</param>
        /// <param name="description">Description of codevalue.</param>
        /// <param name="language">Language used in the description in the format en, dk, us etc. </param>
        public CodeType(string value, string description, string language)
        {
            if (!String.IsNullOrEmpty(value) & !String.IsNullOrEmpty(description) & !String.IsNullOrEmpty(language))
            {
                SDMX_Common.IDType code = new SDMX_Common.IDType(value);
                _value = code;

                SDMX_Common.TextType desc = new SDMX_Common.TextType(description, language);
                _description.Add(desc);
            }
            else
            {
                throw new Exception("Attribute value and element description are required in CodeType!");
            }

            _description = new List<SDMX_Common.TextType>();
        }

        /// <summary>
        /// Annotations.
        /// </summary>
        public SDMX_Common.AnnotationsType Annotations
        {
            get { return _annotations; }
            set { _annotations = value; }
        }

        /// <summary>
        /// Parentcode for the current code in the same codelist.
        /// </summary>
        public SDMX_Common.IDType ParentCode
        {
            get { return _parentCode; }
            set { _parentCode = value; }
        }

        /// <summary>
        /// Urn.
        /// </summary>
        public string Urn
        {
            get { return _urn; }
            set { _urn = value; }
        }

        /// <summary>
        /// Description 
        /// </summary>
        public List<SDMX_Common.TextType> Description
        {
            get { return _description; }
            set { _description = value; }
        }

        /// <summary>
        /// Code value .
        /// </summary>
        public SDMX_Common.IDType Value
        {
            get { return _value; }
            set { _value = value; }
        

        }



    }
}
